import re
from datetime import datetime
from typing import List, Optional, Dict
from pydantic import BaseModel, Field, validator, EmailStr, IPvAnyAddress

from common.utils import is_empty

from enum import Enum

class DelBaseModel(BaseModel):
    uuid: int = Field(..., description="数据的uuid")


class PutLogAlarmRecord(BaseModel):
    uuid: int = Field(..., description="告警记录的uuid")
    comment: Optional[str] = Field("", description="告警记录的说明")


class AlarmLevel(str, Enum):
    # 紧急告警 电话领导
    critical = 'critical'
    # 重要告警 电话
    major = 'major'
    # 一般告警 短信
    warning = 'warning'
    # 信息告警 企业微信
    info = 'info'
    # 无告警
    nothing = 'nothing'
   
    
class ServerType(str, Enum):
    type1 = '应用服务'
    type2 = '大数据服务'
    type3 = '数据库服务'
    


class PostLogAlarmWebhook(BaseModel):
    service_name: str = Field(..., description="服务名称")
    log_type: str = Field(..., description="服务类型")
    error_count: int = Field(..., description="错误日志数量")
    cst_begin_time: str = Field(..., description="告警开始的事件字符串")
    cst_end_time: str = Field(..., description="告警结束的事件字符串")
    alarm_threshold: int = Field(..., description="错误日志阈值")
    error_message: str = Field(..., description="错误日志")
    app_url: str = Field(..., description="访问地址")
    
    

class PostLogAlarmNotice(BaseModel):
    name: str = Field(..., description="服务名称")
    server_type: ServerType = Field(ServerType.type1, description="服务类型")
    level: AlarmLevel = Field(AlarmLevel.info, description="告警级别: critical(领导电话)/major(电话)/warning(短信)/info(企业微信)/nothing(无告警)")
    notice_teams_uuid: List[int] = Field(..., description="通知小组")
    maintain_begin: Optional[datetime] = Field(None, description="告警屏蔽开始时间")
    maintain_end: Optional[datetime] = Field(None, description="告警屏蔽结束时间")
    department: str = Field(..., description="所属部门")
    comment: Optional[str] = Field("", description="日志告警通知说明")
  
    
class PutLogAlarmNotice(PostLogAlarmNotice):
    uuid: int = Field(..., description="告警记录的uuid")
    
    
    
class PutLogAlarmMaintain(BaseModel):
    name: str = Field(..., description="服务名称")
    maintain_begin: Optional[datetime] = Field(None, description="告警屏蔽开始时间")
    maintain_end: Optional[datetime] = Field(None, description="告警屏蔽结束时间")



class PutN9eAlarmRecord(BaseModel):
    fingerprint: str = Field(..., description="告警指纹")
    maintain_begin: Optional[datetime] = Field(None, description="告警屏蔽开始时间")
    maintain_end: Optional[datetime] = Field(None, description="告警屏蔽结束时间")
    comment: Optional[str] = Field("", description="告警记录说明")